package lumis.service.wsrp.producer;

import lumis.doui.control.tabulardata.AdvancedTabularDataControl;
import lumis.doui.source.ISourceData;
import lumis.doui.source.TabularSource;
import lumis.portal.PortalException;
import lumis.portal.manager.ManagerFactory;
import lumis.portal.serviceinterface.IServiceInterfaceUrl;
import lumis.portal.serviceinterfaceinstance.ServiceInterfaceInstanceConfig;

/**
 * {@link AdvancedTabularDataControl} created to treat the row hyperlink
 * creation using the <code>href</code> field to represent the row link.
 * 
 * @version $Revision: 11180 $ $Date: 2009-12-04 18:13:02 -0200 (Fri, 04 Dec 2009) $
 * @since 5.5.0
 */
public class ProducerAdminListTabularDataControl extends AdvancedTabularDataControl
{
	@SuppressWarnings("unchecked")
	@Override
	protected String getFieldHyperlink(TabularSource source, ISourceData row, String fieldId, String compositePrimaryKey, int rowIndex)
			throws PortalException
	{
		String serviceInterfaceInstanceId = row.get("serviceInterfaceInstanceId", String.class);
		ServiceInterfaceInstanceConfig serviceInterfaceInstanceConfig = ManagerFactory.getServiceInterfaceInstanceManager().get(
				source.getSourceContext().getSessionConfig(), serviceInterfaceInstanceId, source.getSourceContext().getTransaction());
		String pageId = serviceInterfaceInstanceConfig.getPageId();
		IServiceInterfaceUrl url = source.getDouiContext().getRenderResponse().createRenderURL();
		url.setTargetScope(IServiceInterfaceUrl.TARGET_SCOPE_PAGE, pageId);
		url.setPageId(pageId);
		return url.toString();
	}
}
